import pytest
import requests

def setup_function(self):
    print("开始执行函数")

def teardown_function(self):
    print("结束函数开始执行")

class Test_A3mall():
    token1=""
    def setup_class(self):
        print("开始执行")
    def teardown_class(self):
        print("结束执行")
    # 登录
    def test_login(self):
        url="http://10.59.9.14:7003/api/public/login"
        data={"username": "19064013675","password": "123456"}
        res=requests.post(url=url,json=data)

        Test_A3mall.token1="Bearer "+res.json()['data']['token']
        print(Test_A3mall.token1)

    # 查看积分列表
    def test_integral(self):
        url="http://10.59.9.14:7003/api/point?page=1&type=0&sort=1"
        tou={"auth-token":Test_A3mall.token1}
        res=requests.get(url=url,headers=tou)

        assert "注册会员" not in res.text
    # 商品详情
    def test_goods(self):
        url="http://10.59.9.14:7003/api/point/view?id=7"
        tou = {"auth-token": Test_A3mall.token1}
        res = requests.get(url=url, headers=tou)

        assert "会员" != res.text

    # 创建订单
    def test_dingdan(self):
        url="http://10.59.9.14:7003/api/order/confirm?id=7&type=point&sku_id=&num=1&shipping_type=1"
        tou = {"auth-token": Test_A3mall.token1}
        res = requests.get(url=url, headers=tou)
        print(res.text)


    # 支付
    def test_create(self):
        url="http://10.59.9.14:7003/api/order/create"
        tou = {"auth-token": Test_A3mall.token1}
        data={
  "id": "7",
  "type": "point",
  "address_id": 293,
  "store_id": 2,
  "shipping_type": 1,
  "bonus_id": "0",
  "payment": "balance",
  "remarks": "",
  "source": 1,
  "url": "http://10.59.9.14:7003/wap/pages/cart/confirm?id=7&sku_id=&num=1&type=point",
  "sku_id": "",
  "num": "1"
}
        res=requests.post(url=url,headers=tou,json=data)
        assert "支付成功" in res.text
        print(res.text)

def test_asd():
    print("函数级别调用")
a=test_asd()

if __name__ == '__main__':
    pytest.main(['3'],'-s')